package com.pgeneral.user.management.controller;

import com.pgeneral.user.management.config.ResultBean;
import com.pgeneral.user.management.entity.UserSopRole;
import com.pgeneral.user.management.service.UserSoproleService;
import com.pgeneral.user.management.vo.UserSopRoleScopeVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 角色表
 *
 * @author lenovo
 */
@Slf4j
@RestController
@RequestMapping("/user/sopRole")
public class UserSopRoleController {

    @Autowired
    private UserSoproleService service;

    /**
     * 查询角色所在权限
     *
     * @return
     */
//    @LogAnnotation(module="/user/sopRole",operator = "/getInfo 查询所有角色信息,如果没有权限返回空List")
    @GetMapping(value = "/getInfoByRoleId")
    public ResultBean getInfoByRoleId(@RequestParam(value = "roleId") String roleId) {
        log.info("查询角色所在权限");
        List<UserSopRoleScopeVO> userSopScopeDataList = service.getInfoByRoleId(roleId);
        return ResultBean.Success(userSopScopeDataList);

    }

    /**
     * 查询所有角色信息,如果没有角色返回空List
     *
     * @return
     */
//    @LogAnnotation(module="/user/sopRole",operator = "/getInfo 查询所有角色信息,如果没有权限返回空List")
    @GetMapping(value = "/getInfo")
    public ResultBean getUserSopRoleAll() {
        log.info("查询所有角色信息,如果没有角色返回空List");
        List<UserSopRole> userSopScopeDataList = service.getUserSopRoleAll();
        return ResultBean.Success(userSopScopeDataList);

    }

    /**
     * 删除角色 并且删除角色所对应的权限
     *
     * @return
     */
    @PostMapping(value = "/deleteInfo")
    public ResultBean deleteInfoByRoleId(@RequestParam(value = "roleId") String roleId) {
        log.info("删除角色 并且删除角色所对应的权限,参数：【{}】", roleId);
        int result = service.deleteInfoByRoleId(roleId);
        return ResultBean.InsertSuccessResult(result);

    }
}
